package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @program: rocsun
 * @description:
 * @author: yx.guo
 * @create: 2025-03-13 20:37
 **/
public class IO_Study {

    public static final String FILE_NAME = "/Users/yx.guo/Documents/study/test.txt";

    public static void main(String[] args) throws IOException {
        test();
    }

    public static void test() throws IOException {

        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Paths.get(FILE_NAME)), StandardCharsets.UTF_8));
        bufferedWriter.write("hello world!");
        bufferedWriter.flush();
        bufferedWriter.close();


        FileInputStream fileInputStream = new FileInputStream(FILE_NAME);
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
        int data;
        while ((data = inputStreamReader.read()) != -1) {
            System.out.println((char) data);
        }

    }


}
